package com.xqboss.apps.service.nft;


import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xqboss.apps.domain.nft.NftUsedRecord;
import com.xqboss.apps.mapper.nft.NftUsedRecordMapper;

import java.util.Date;


/**
 * nft-使用记录(NftUsedRecord)表服务实现类
 *
 * @author makejava
 * @since 2023-12-15 15:07:30
 */
@Service
public class NftUsedRecordService extends ServiceImpl<NftUsedRecordMapper, NftUsedRecord> {

    /**
     * 获取nft使用记录
     * @param nftNumberId
     * @return
     */
    public NftUsedRecord getByNftNumberId(Long nftNumberId) {
        return this.lambdaQuery().eq(NftUsedRecord::getNftNumberId, nftNumberId).one();
    }

    /**
     * 已奖励
     * @param nftNumberId
     * @return
     */
    public boolean isReward(Long nftNumberId) {
        return this.lambdaUpdate()
                .set(NftUsedRecord::getIsReward, 1)
                .set(NftUsedRecord::getRewardTime, new Date())
                .eq(NftUsedRecord::getNftNumberId, nftNumberId)
                .eq(NftUsedRecord::getIsReward, 0)
                .update();
    }
}
